package com.jumlabs.presentation.backend.web.catalogs.auth;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jumlabs.entities.auth.Group;
import com.jumlabs.services.auth.GroupService;
@RequestMapping(value="/grupos")
@Controller
public class GroupController {
	@Autowired
	GroupService groupService;
	
	
	@RequestMapping(method=RequestMethod.GET)
	public String list(){
		return "groups";
	}
	
	@RequestMapping(method=RequestMethod.GET, params={"type=json","paginated=true"})
	public @ResponseBody Map<Object,Object> getGroupsJSON(
			@RequestParam int iDisplayLength, @RequestParam int iDisplayStart,int sEcho){
		int page=com.jumlabs.util.data.Pagination.calcPage(iDisplayStart,iDisplayLength);
		Page<Group> groupPage=groupService.getGroupsPaginated(page, iDisplayLength);
		Map<Object,Object> result=com.jumlabs.util.data.Pagination.getDataTablesFormattedMap(iDisplayStart, iDisplayLength, sEcho, groupPage);
		return result;
	}
}
